import java.util.HashSet;
import java.util.Set;

public class Test26 {
    public int findSubstringInWraproundString(String ss) {
        int n = ss.length();
        char[] s = ss.toCharArray();
        int[] dp = new int[n];
        int[] arr = new int[26];
        dp[0] = 1;
        arr[s[0] - 'a'] = 1;
        int count = 0;
        for(int i = 1;i < n;i++) {
            if(s[i] != 'a') {
                if(s[i] - s[i - 1] == 1) dp[i] = dp[i - 1];
            }else {
                if(s[i - 1] == 'z') {
                    dp[i] = dp[i - 1];
                }
            }
            dp[i] += 1;
            arr[s[i] - 'a'] = arr[s[i] - 'a'] > dp[i] ? arr[s[i] - 'a'] : dp[i];
        }
        for(int i = 0;i < 26;i++) {
            count += arr[i];
        }
        return count;
    }

    public static void main(String[] args) {
        Test26 test26 = new Test26();
        String s = "aabb";
        test26.findSubstringInWraproundString(s);
    }
}
